package com.zat.mes.andrmes.dofun.work.vm

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.love.zywanandroid.retrofit.RetrofitManager
import com.love.zywanandroid.retrofit.api.ApiService
import com.zat.mes.andrmes.BomNotifiBean
import com.zat.mes.andrmes.data.*
import com.zat.mes.andrmes.retrofit.callback.MesCallBack
import okhttp3.RequestBody
import retrofit2.Call
import retrofit2.Response

/**
 * @author zy
 * @date :2021-02-22
 * @description: 原料领用通知单
 */
class GetBomNotifiModel(application: Application) : AndroidViewModel(application){

    private val getJiagong: MutableLiveData<MutableList<GetBomNotifiBean>> = MutableLiveData()
    private val getOrderBomDetail:MutableLiveData<MutableList<GetBomDetail>> = MutableLiveData()



    fun getJiagongData(): LiveData<MutableList<GetBomNotifiBean>> {
        return getJiagong
    }
    fun getOrderBomDetailList():LiveData<MutableList<GetBomDetail>>{
        return getOrderBomDetail
    }

    /**
     * 根据制单号查询加工单
     */
    fun getJiagong(orderNo: String?) {
        RetrofitManager.apiService(ApiService::class.java)
            .getOrderJiagong(orderNo)
            .enqueue(object : MesCallBack<BaseResponse<MutableList<GetBomNotifiBean>>>() {
                override fun onSuccessful(
                    call: Call<BaseResponse<MutableList<GetBomNotifiBean>>>?,
                    response: Response<BaseResponse<MutableList<GetBomNotifiBean>>>?
                ) {
                    val result = response?.body()?.result
                    getJiagong.postValue(result)
                }

            })
    }

    /**
     * 根据加工单查询领料通知单
     */
    fun getOrderBomDetail(yarnInformNo: String?) {
        RetrofitManager.apiService(ApiService::class.java)
            .getOrderBomDetail(yarnInformNo)
            .enqueue(object : MesCallBack<BaseResponse<MutableList<GetBomDetail>>>() {
                override fun onSuccessful(
                    call: Call<BaseResponse<MutableList<GetBomDetail>>>?,
                    response: Response<BaseResponse<MutableList<GetBomDetail>>>?
                ) {
                    val result = response?.body()?.result
                    getOrderBomDetail.postValue(result)
                }

            })
    }



}